﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMIS.Entities;
using SMIS.Dals;

namespace SMIS
{
    public partial class FormJob : Form
    {
        public FormJob()
        {
            InitializeComponent();
        }

        private void FormJob_Load(object sender, EventArgs e)
        {
            List<Job> jobs = Dal4Job.SearchAllJobs();
            gvJobs.DataSource = jobs;
        }

        //【高月 2013-3-31-165323】工种修改按钮事件
        private void button1_Click(object sender, EventArgs e)
        {
            Job selectedJob = gvJobs.SelectedRows[0].DataBoundItem as Job;

            if (gvJobs.SelectedRows.Count == 0)
                MessageBox.Show("请选择要修改的行！", "提示");
            else
            {
                ModifyJob modifyJob = new ModifyJob();
                modifyJob.MdfID = selectedJob.ID;
                modifyJob.MdfName = selectedJob.Name;
                modifyJob.MdfDes = selectedJob.Des;

                modifyJob.ShowDialog();
            }
        }

        //【高月 2013-3-31-165323】工种删除按钮事件，需判断员工信息中是否包含有将要删除的工种
        private void button2_Click(object sender, EventArgs e)
        {
            if (gvJobs.SelectedRows.Count == 0)
                MessageBox.Show("请选择要删除的行！", "提示");
            else
            {
                Job selectedjob = gvJobs.SelectedRows[0].DataBoundItem as Job;
                if(MessageBox.Show(string.Format("确定要删除工种【{0}】的信息吗？",selectedjob.Name), "确认信息",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Question)== DialogResult.OK)
                {
                    if (Dal4Job.DeleteSelectedJob(selectedjob) == true)
                        MessageBox.Show(string.Format("恭喜你删除工种【{0}】的信息成功！",selectedjob.Name),"提示");
                    else
                    {
                        MessageBox.Show("删除工种失败，请先删除与此工种相关的员工", "提示");
                    }
                }  
            }
        }

        //取消按钮
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
